/* @LICENSE(NICTA_CORE) */

#include <stdio.h>
#include <stdint.h>

extern int __fputc(int c, FILE *stream);

static size_t
platform_write(void *data, long int position, size_t count, void *handle)
{
    size_t i;
    char *real_data = data;
    for (i = 0; i < count; i++)
        __fputc(real_data[i], 0);
    return count;
}

struct __file __stdin = {
    .handle            = NULL,
    .read_fn           = NULL,
    .write_fn          = NULL,
    .close_fn          = NULL,
    .eof_fn            = NULL,
    .buffering_mode    = _IONBF,
    .buffer            = NULL,
    .unget_pos         = 0,
    .current_pos       = 0,
    .eof               = 0
};

struct __file __stdout = {
    .handle            = NULL,
    .read_fn           = NULL,
    .write_fn          = platform_write,
    .close_fn          = NULL,
    .eof_fn            = NULL,
    .buffering_mode    = _IONBF,
    .buffer            = NULL,
    .unget_pos         = 0,
    .current_pos       = 0,
    .eof               = 0
};

struct __file __stderr = {
    .handle            = NULL,
    .read_fn           = NULL,
    .write_fn          = platform_write,
    .close_fn          = NULL,
    .eof_fn            = NULL,
    .buffering_mode    = _IONBF,
    .buffer            = NULL,
    .unget_pos         = 0,
    .current_pos       = 0,
    .eof               = 0
};

FILE *stdin = &__stdin;
FILE *stdout = &__stdout;
FILE *stderr = &__stderr;
